package com.hzj.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hzj.pojo.OrderInfo;
import com.hzj.pojo.UserInfo;
import com.hzj.pojo.vo.user.OrderCountQueryVo;
import com.hzj.service.*;
import com.hzj.utils.Result;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/consumer/admin/order/orderInfo/")
public class OrderInfoController {

    @Autowired
    private OrderInfoService ois;
    @Autowired
    private UserInfoService uis;

    @Autowired
    private UserLoginRecordService urs;


    @RequestMapping("getStatusList")
    public Result getStatusList() {
        return ois.queryOrderInfo();
    }

    @RequestMapping("submitOrder/{scheduleId}/{patientId}")
    public Result submitOrder(@PathVariable int page, @PathVariable int limit, @RequestParam(required = false) Long patientId, @RequestParam(required = false) Integer orderStatus) {
        return ois.queryByScheduleIdPatientId(page, limit, patientId, orderStatus);
    }

    @RequestMapping("{page}/{limit}")
    public Result queryByPageLimit(@PathVariable int page, @PathVariable int limit, @RequestParam(required = false) Long patientId, @RequestParam(required = false) Integer orderStatus) {
        return ois.queryByPageLimit(page, limit, patientId, orderStatus);
    }

    @RequestMapping("getOrderInfo/{orderId}")
    public OrderInfo queryById(@PathVariable Long orderId) {
        return ois.queryById(orderId);
    }

    @RequestMapping("cancelOrder/{orderId}")
    public Result updateById(@PathVariable Long orderId) {
        return ois.updateById(orderId);
    }

    @PostMapping("saveOrderInfo")
    public boolean saveOrderInfo(@RequestBody OrderInfo orderInfo) {
        return ois.saveOrderInfo(orderInfo);
    }

    @PostMapping("atformapi/order/orderInfo/auth/updateOrderByHosRecordId")
    public boolean updateOrderByHosRecordId(@RequestBody OrderInfo orderInfo) {
        return ois.updateOrderByHosRecordId(orderInfo);
    }

    @PostMapping("queryAll/{page}/{limit}")
    public Result queryAll(@PathVariable int page, @PathVariable int limit, @RequestParam(required = false) String patientName, @RequestParam(required = false) String hosname) {
//        System.out.println("====>"+patientName+"|"+hosname);

        Result<IPage> result = ois.queryAll(page, limit, patientName, hosname);


        return result;
    }
    @PostMapping("/selectCount")
    public Result selectCount(){

        Map<String,Object> map1=new HashMap<String,Object>();
        Map<String,Object> map2=new HashMap<String,Object>();
        Map<String,Object> map3=new HashMap<String,Object>();
        Map<String,Object> map4=new HashMap<String,Object>();
        Integer num1 = ois.selectCountOne();
        Integer num2 = ois.selectCountTwo();
        Integer num3 = ois.selectCountThree();
        Integer num4 = urs.selectUserLoginRecord();
        map1.put("value",num1);
        map1.put("name","预约订单");
        map2.put("value",num2);
        map2.put("name","支付订单");
        map3.put("value",num3);
        map3.put("name","退款订单");
        map4.put("value",num4);
        map4.put("name","用户登录次数");
        List<Map> list=new ArrayList<Map>();
        list.add(map1);
        list.add(map2);
        list.add(map3);
        list.add(map4);
        return Result.ok(list);
    }

    @PostMapping ("getCountMap")
    public Result getCountMap(@ApiParam(name = "orderCountQueryVo", value = "查询对象", required = false) OrderCountQueryVo orderCountQueryVo) {
        System.out.println("OrderCountQueryVo"+orderCountQueryVo);
        return Result.ok(ois.getCountMap(orderCountQueryVo));
    }

}
